import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
import 'package:shudu/utils/global.dart';
import 'package:shudu/utils/image_utils.dart';
import 'package:shudu/widget/sudoku/generator.dart';

class SuccessPage extends StatelessWidget {
  final LEVEL level;
  final int countdownNum;

  SuccessPage(this.level, this.countdownNum);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: mainColor,
      body: SafeArea(
          child: Stack(
        children: [
          Positioned(
            bottom: 0,
            child: loadAssetImage("mask", width: Get.width),
          ),
          Column(
            children: [
              const SizedBox(
                height: 10,
              ),
              const Text(
                "数独大师",
                style: TextStyle(color: Colors.white, fontSize: 16),
              ),
              loadAssetImage("success"),
              const Text(
                "恭喜过关",
                style: TextStyle(color: Colors.white, fontSize: 32),
              ),
              const SizedBox(
                height: 20,
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  _itemWidget(levelName[level] ?? "", "模式"),
                  Container(
                    width: 1,
                    height: 14,
                    color: Colors.white.withOpacity(0.8),
                  ),
                  _itemWidget(durationStr(countdownNum), "用时")
                ],
              ),
              const Spacer(),
            ],
          ),
          Positioned(
              bottom: 150,
              left: 0,
              right: 0,
              child: Column(
                children: [
                  GestureDetector(
                    child: Container(
                      width: 264,
                      height: 52,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(12)),
                      child: const Text(
                        "再来一局",
                        style: TextStyle(color: mainColor, fontSize: 16),
                      ),
                    ),
                    onTap: () {
                      Get.back(result: true);
                    },
                  ),
                  const SizedBox(
                    height: 15,
                  ),
                  GestureDetector(
                    onTap: () {
                      Get.back();
                      Get.back();
                    },
                    child: Container(
                      width: 264,
                      height: 52,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          border: Border.all(color: Colors.white),
                          borderRadius: BorderRadius.circular(12)),
                      child: const Text(
                        "返回首页",
                        style: TextStyle(color: Colors.white, fontSize: 16),
                      ),
                    ),
                  )
                ],
              ))
        ],
      )),
    );
  }

  Widget _itemWidget(String title, String desc) {
    return Column(
      children: [
        Text(
          title,
          style: const TextStyle(color: Colors.white, fontSize: 20),
        ),
        const SizedBox(
          height: 10,
        ),
        Text(
          desc,
          style: TextStyle(color: Colors.white.withOpacity(0.7), fontSize: 11),
        ),
      ],
    );
  }
}
